  1: <?php
  2: /* SVN FILE: $Id$ */
  3: /**
  4:  * Short description for file.
  5:  *
  6:  * Long description for file
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.libs
 20:  * @since         CakePHP(tm) v 1.2.0.4116
 21:  * @version       $Revision$
 22:  * @modifiedby    $LastChangedBy$
 23:  * @lastmodified  $Date$
 24:  * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 25:  */
 26: /**
 27:  * Short description for file.
 28:  *
 29:  * Long description for file
 30:  *
 31:  * @package       cake
 32:  * @subpackage    cake.cake.libs
 33:  */
 34: class L10n extends Object {
 35: /**
 36:  * The language for current locale
 37:  *
 38:  * @var string
 39:  * @access public
 40:  */
 41:     var $language = 'English (United States)';
 42: /**
 43:  * Locale search paths
 44:  *
 45:  * @var array
 46:  * @access public
 47:  */
 48:     var $languagePath = array('eng');
 49: /**
 50:  * ISO 639-3 for current locale
 51:  *
 52:  * @var string
 53:  * @access public
 54:  */
 55:     var $lang = 'eng';
 56: /**
 57:  * Locale
 58:  *
 59:  * @var string
 60:  * @access public
 61:  */
 62:     var $locale = 'en_us';
 63: /**
 64:  * Default ISO 639-3 language.
 65:  *
 66:  * DEFAULT_LANGUAGE is defined in an application this will be set as a fall back
 67:  *
 68:  * @var string
 69:  * @access public
 70:  */
 71:     var $default = null;
 72: /**
 73:  * Encoding used for current locale
 74:  *
 75:  * @var string
 76:  * @access public
 77:  */
 78:     var $charset = 'utf-8';
 79: /**
 80:  * Set to true if a locale is found
 81:  *
 82:  * @var string
 83:  * @access public
 84:  */
 85:     var $found = false;
 86: /**
 87:  * Maps ISO 639-3 to I10n::__l10nCatalog
 88:  *
 89:  * @var array
 90:  * @access private
 91:  */
 92:     var $__l10nMap = array(/* Afrikaans */ 'afr' => 'af',
 93:                                 /* Albanian */ 'alb' => 'sq',
 94:                                 /* Arabic */ 'ara' => 'ar',
 95:                                 /* Armenian - Armenia */ 'hye' => 'hy',
 96:                                 /* Basque */ 'baq' => 'eu',
 97:                                 /* Bosnian */ 'bos' => 'bs',
 98:                                 /* Bulgarian */ 'bul' => 'bg',
 99:                                 /* Byelorussian */ 'bel' => 'be',
100:                                 /* Catalan */ 'cat' => 'ca',
101:                                 /* Chinese */ 'chi' => 'zh',
102:                                 /* Chinese */ 'zho' => 'zh',
103:                                 /* Croatian */ 'hrv' => 'hr',
104:                                 /* Czech */ 'cze' => 'cs',
105:                                 /* Czech */ 'ces' => 'cs',
106:                                 /* Danish */ 'dan' => 'da',
107:                                 /* Dutch (Standard) */ 'dut' => 'nl',
108:                                 /* Dutch (Standard) */ 'nld' => 'nl',
109:                                 /* English */ 'eng' => 'en',
110:                                 /* Estonian */ 'est' => 'et',
111:                                 /* Faeroese */ 'fao' => 'fo',
112:                                 /* Farsi */ 'fas' => 'fa',
113:                                 /* Farsi */ 'per' => 'fa',
114:                                 /* Finnish */ 'fin' => 'fi',
115:                                 /* French (Standard) */ 'fre' => 'fr',
116:                                 /* French (Standard) */ 'fra' => 'fr',
117:                                 /* Gaelic (Scots) */ 'gla' => 'gd',
118:                                 /* Galician */ 'glg' => 'gl',
119:                                 /* German (Standard) */ 'deu' => 'de',
120:                                 /* German (Standard) */ 'ger' => 'de',
121:                                 /* Greek */ 'gre' => 'el',
122:                                 /* Greek */ 'ell' => 'el',
123:                                 /* Hebrew */ 'heb' => 'he',
124:                                 /* Hindi */ 'hin' => 'hi',
125:                                 /* Hungarian */ 'hun' => 'hu',
126:                                 /* Icelandic */ 'ice' => 'is',
127:                                 /* Icelandic */ 'isl' => 'is',
128:                                 /* Indonesian */ 'ind' => 'id',
129:                                 /* Irish */ 'gle' => 'ga',
130:                                 /* Italian */ 'ita' => 'it',
131:                                 /* Japanese */ 'jpn' => 'ja',
132:                                 /* Korean */ 'kor' => 'ko',
133:                                 /* Latvian */ 'lav' => 'lv',
134:                                 /* Lithuanian */ 'lit' => 'lt',
135:                                 /* Macedonian */ 'mac' => 'mk',
136:                                 /* Macedonian */ 'mkd' => 'mk',
137:                                 /* Malaysian */ 'may' => 'ms',
138:                                 /* Malaysian */ 'msa' => 'ms',
139:                                 /* Maltese */ 'mlt' => 'mt',
140:                                 /* Norwegian */ 'nor' => 'no',
141:                                 /* Norwegian Bokmal */ 'nob' => 'nb',
142:                                 /* Norwegian Nynorsk */ 'nno' => 'nn',
143:                                 /* Polish */ 'pol' => 'pl',
144:                                 /* Portuguese (Portugal) */ 'por' => 'pt',
145:                                 /* Rhaeto-Romanic */ 'roh' => 'rm',
146:                                 /* Romanian */ 'rum' => 'ro',
147:                                 /* Romanian */ 'ron' => 'ro',
148:                                 /* Russian */ 'rus' => 'ru',
149:                                 /* Sami (Lappish) */ 'smi' => 'sz',
150:                                 /* Serbian */ 'scc' => 'sr',
151:                                 /* Serbian */ 'srp' => 'sr',
152:                                 /* Slovak */ 'slo' => 'sk',
153:                                 /* Slovak */ 'slk' => 'sk',
154:                                 /* Slovenian */ 'slv' => 'sl',
155:                                 /* Sorbian */ 'wen' => 'sb',
156:                                 /* Spanish (Spain - Traditional) */ 'spa' => 'es',
157:                                 /* Swedish */ 'swe' => 'sv',
158:                                 /* Thai */ 'tha' => 'th',
159:                                 /* Tsonga */ 'tso' => 'ts',
160:                                 /* Tswana */ 'tsn' => 'tn',
161:                                 /* Turkish */ 'tur' => 'tr',
162:                                 /* Ukrainian */ 'ukr' => 'uk',
163:                                 /* Urdu */ 'urd' => 'ur',
164:                                 /* Venda */ 'ven' => 've',
165:                                 /* Vietnamese */ 'vie' => 'vi',
166:                                 /* Welsh */ 'cym' => 'cy',
167:                                 /* Xhosa */ 'xho' => 'xh',
168:                                 /* Yiddish */ 'yid' => 'yi',
169:                                 /* Zulu */ 'zul' => 'zu');
170: /**
171:  * HTTP_ACCEPT_LANGUAGE catalog
172:  *
173:  * holds all information related to a language
174:  *
175:  * @var array
176:  * @access private
177:  */
178:     var $__l10nCatalog = array('af' => array('language' => 'Afrikaans', 'locale' => 'afr', 'localeFallback' => 'afr', 'charset' => 'utf-8'),
179:                                         'ar' => array('language' => 'Arabic', 'locale' => 'ara', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
180:                                         'ar-ae' => array('language' => 'Arabic (U.A.E.)', 'locale' => 'ar_ae', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
181:                                         'ar-bh' => array('language' => 'Arabic (Bahrain)', 'locale' => 'ar_bh', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
182:                                         'ar-dz' => array('language' => 'Arabic (Algeria)', 'locale' => 'ar_dz', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
183:                                         'ar-eg' => array('language' => 'Arabic (Egypt)', 'locale' => 'ar_eg', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
184:                                         'ar-iq' => array('language' => 'Arabic (Iraq)', 'locale' => 'ar_iq', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
185:                                         'ar-jo' => array('language' => 'Arabic (Jordan)', 'locale' => 'ar_jo', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
186:                                         'ar-kw' => array('language' => 'Arabic (Kuwait)', 'locale' => 'ar_kw', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
187:                                         'ar-lb' => array('language' => 'Arabic (Lebanon)', 'locale' => 'ar_lb', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
188:                                         'ar-ly' => array('language' => 'Arabic (Libya)', 'locale' => 'ar_ly', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
189:                                         'ar-ma' => array('language' => 'Arabic (Morocco)', 'locale' => 'ar_ma', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
190:                                         'ar-om' => array('language' => 'Arabic (Oman)', 'locale' => 'ar_om', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
191:                                         'ar-qa' => array('language' => 'Arabic (Qatar)', 'locale' => 'ar_qa', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
192:                                         'ar-sa' => array('language' => 'Arabic (Saudi Arabia)', 'locale' => 'ar_sa', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
193:                                         'ar-sy' => array('language' => 'Arabic (Syria)', 'locale' => 'ar_sy', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
194:                                         'ar-tn' => array('language' => 'Arabic (Tunisia)', 'locale' => 'ar_tn', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
195:                                         'ar-ye' => array('language' => 'Arabic (Yemen)', 'locale' => 'ar_ye', 'localeFallback' => 'ara', 'charset' => 'utf-8'),
196:                                         'be' => array('language' => 'Byelorussian', 'locale' => 'bel', 'localeFallback' => 'bel', 'charset' => 'utf-8'),
197:                                         'bg' => array('language' => 'Bulgarian', 'locale' => 'bul', 'localeFallback' => 'bul', 'charset' => 'utf-8'),
198:                                         'bs' => array('language' => 'Bosnian', 'locale' => 'bos', 'localeFallback' => 'bos', 'charset' => 'utf-8'),
199:                                         'ca' => array('language' => 'Catalan', 'locale' => 'cat', 'localeFallback' => 'cat', 'charset' => 'utf-8'),
200:                                         'cs' => array('language' => 'Czech', 'locale' => 'cze', 'localeFallback' => 'cze', 'charset' => 'utf-8'),
201:                                         'da' => array('language' => 'Danish', 'locale' => 'dan', 'localeFallback' => 'dan', 'charset' => 'utf-8'),
202:                                         'de' => array('language' => 'German (Standard)', 'locale' => 'deu', 'localeFallback' => 'deu', 'charset' => 'utf-8'),
203:                                         'de-at' => array('language' => 'German (Austria)', 'locale' => 'de_at', 'localeFallback' => 'deu', 'charset' => 'utf-8'),
204:                                         'de-ch' => array('language' => 'German (Swiss)', 'locale' => 'de_ch', 'localeFallback' => 'deu', 'charset' => 'utf-8'),
205:                                         'de-de' => array('language' => 'German (Germany)', 'locale' => 'de_de', 'localeFallback' => 'deu', 'charset' => 'utf-8'),
206:                                         'de-li' => array('language' => 'German (Liechtenstein)', 'locale' => 'de_li', 'localeFallback' => 'deu', 'charset' => 'utf-8'),
207:                                         'de-lu' => array('language' => 'German (Luxembourg)', 'locale' => 'de_lu', 'localeFallback' => 'deu', 'charset' => 'utf-8'),
208:                                         'e' => array('language' => 'Greek', 'locale' => 'gre', 'localeFallback' => 'gre', 'charset' => 'utf-8'),
209:                                         'el' => array('language' => 'Greek', 'locale' => 'gre', 'localeFallback' => 'gre', 'charset' => 'utf-8'),
210:                                         'en' => array('language' => 'English', 'locale' => 'eng', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
211:                                         'en-au' => array('language' => 'English (Australian)', 'locale' => 'en_au', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
212:                                         'en-bz' => array('language' => 'English (Belize)', 'locale' => 'en_bz', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
213:                                         'en-ca' => array('language' => 'English (Canadian)', 'locale' => 'en_ca', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
214:                                         'en-gb' => array('language' => 'English (British)', 'locale' => 'en_gb', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
215:                                         'en-ie' => array('language' => 'English (Ireland)', 'locale' => 'en_ie', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
216:                                         'en-jm' => array('language' => 'English (Jamaica)', 'locale' => 'en_jm', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
217:                                         'en-nz' => array('language' => 'English (New Zealand)', 'locale' => 'en_nz', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
218:                                         'en-tt' => array('language' => 'English (Trinidad)', 'locale' => 'en_tt', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
219:                                         'en-us' => array('language' => 'English (United States)', 'locale' => 'en_us', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
220:                                         'en-za' => array('language' => 'English (South Africa)', 'locale' => 'en_za', 'localeFallback' => 'eng', 'charset' => 'utf-8'),
221:                                         'es' => array('language' => 'Spanish (Spain - Traditional)', 'locale' => 'spa', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
222:                                         'es-ar' => array('language' => 'Spanish (Argentina)', 'locale' => 'es_ar', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
223:                                         'es-bo' => array('language' => 'Spanish (Bolivia)', 'locale' => 'es_bo', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
224:                                         'es-cl' => array('language' => 'Spanish (Chile)', 'locale' => 'es_cl', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
225:                                         'es-co' => array('language' => 'Spanish (Colombia)', 'locale' => 'es_co', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
226:                                         'es-cr' => array('language' => 'Spanish (Costa Rica)', 'locale' => 'es_cr', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
227:                                         'es-do' => array('language' => 'Spanish (Dominican Republic)', 'locale' => 'es_do', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
228:                                         'es-ec' => array('language' => 'Spanish (Ecuador)', 'locale' => 'es_ec', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
229:                                         'es-es' => array('language' => 'Spanish (Spain)', 'locale' => 'es_es', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
230:                                         'es-gt' => array('language' => 'Spanish (Guatemala)', 'locale' => 'es_gt', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
231:                                         'es-hn' => array('language' => 'Spanish (Honduras)', 'locale' => 'es_hn', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
232:                                         'es-mx' => array('language' => 'Spanish (Mexican)', 'locale' => 'es_mx', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
233:                                         'es-ni' => array('language' => 'Spanish (Nicaragua)', 'locale' => 'es_ni', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
234:                                         'es-pa' => array('language' => 'Spanish (Panama)', 'locale' => 'es_pa', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
235:                                         'es-pe' => array('language' => 'Spanish (Peru)', 'locale' => 'es_pe', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
236:                                         'es-pr' => array('language' => 'Spanish (Puerto Rico)', 'locale' => 'es_pr', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
237:                                         'es-py' => array('language' => 'Spanish (Paraguay)', 'locale' => 'es_py', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
238:                                         'es-sv' => array('language' => 'Spanish (El Salvador)', 'locale' => 'es_sv', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
239:                                         'es-uy' => array('language' => 'Spanish (Uruguay)', 'locale' => 'es_uy', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
240:                                         'es-ve' => array('language' => 'Spanish (Venezuela)', 'locale' => 'es_ve', 'localeFallback' => 'spa', 'charset' => 'utf-8'),
241:                                         'et' => array('language' => 'Estonian', 'locale' => 'est', 'localeFallback' => 'est', 'charset' => 'utf-8'),
242:                                         'eu' => array('language' => 'Basque', 'locale' => 'baq', 'localeFallback' => 'baq', 'charset' => 'utf-8'),
243:                                         'fa' => array('language' => 'Farsi', 'locale' => 'per', 'localeFallback' => 'per', 'charset' => 'utf-8'),
244:                                         'fi' => array('language' => 'Finnish', 'locale' => 'fin', 'localeFallback' => 'fin', 'charset' => 'utf-8'),
245:                                         'fo' => array('language' => 'Faeroese', 'locale' => 'fao', 'localeFallback' => 'fao', 'charset' => 'utf-8'),
246:                                         'fr' => array('language' => 'French (Standard)', 'locale' => 'fre', 'localeFallback' => 'fre', 'charset' => 'utf-8'),
247:                                         'fr-be' => array('language' => 'French (Belgium)', 'locale' => 'fr_be', 'localeFallback' => 'fre', 'charset' => 'utf-8'),
248:                                         'fr-ca' => array('language' => 'French (Canadian)', 'locale' => 'fr_ca', 'localeFallback' => 'fre', 'charset' => 'utf-8'),
249:                                         'fr-ch' => array('language' => 'French (Swiss)', 'locale' => 'fr_ch', 'localeFallback' => 'fre', 'charset' => 'utf-8'),
250:                                         'fr-fr' => array('language' => 'French (France)', 'locale' => 'fr_fr', 'localeFallback' => 'fre', 'charset' => 'utf-8'),
251:                                         'fr-lu' => array('language' => 'French (Luxembourg)', 'locale' => 'fr_lu', 'localeFallback' => 'fre', 'charset' => 'utf-8'),
252:                                         'ga' => array('language' => 'Irish', 'locale' => 'gle', 'localeFallback' => 'gle', 'charset' => 'utf-8'),
253:                                         'gd' => array('language' => 'Gaelic (Scots)', 'locale' => 'gla', 'localeFallback' => 'gla', 'charset' => 'utf-8'),
254:                                         'gd-ie' => array('language' => 'Gaelic (Irish)', 'locale' => 'gd_ie', 'localeFallback' => 'gla', 'charset' => 'utf-8'),
255:                                         'gl' => array('language' => 'Galician', 'locale' => 'glg', 'localeFallback' => 'glg', 'charset' => 'utf-8'),
256:                                         'he' => array('language' => 'Hebrew', 'locale' => 'heb', 'localeFallback' => 'heb', 'charset' => 'utf-8'),
257:                                         'hi' => array('language' => 'Hindi', 'locale' => 'hin', 'localeFallback' => 'hin', 'charset' => 'utf-8'),
258:                                         'hr' => array('language' => 'Croatian', 'locale' => 'hrv', 'localeFallback' => 'hrv', 'charset' => 'utf-8'),
259:                                         'hu' => array('language' => 'Hungarian', 'locale' => 'hun', 'localeFallback' => 'hun', 'charset' => 'utf-8'),
260:                                         'hy' => array('language' => 'Armenian - Armenia', 'locale' => 'hye', 'localeFallback' => 'hye', 'charset' => 'utf-8'),
261:                                         'id' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8'),
262:                                         'in' => array('language' => 'Indonesian', 'locale' => 'ind', 'localeFallback' => 'ind', 'charset' => 'utf-8'),
263:                                         'is' => array('language' => 'Icelandic', 'locale' => 'ice', 'localeFallback' => 'ice', 'charset' => 'utf-8'),
264:                                         'it' => array('language' => 'Italian', 'locale' => 'ita', 'localeFallback' => 'ita', 'charset' => 'utf-8'),
265:                                         'it-ch' => array('language' => 'Italian (Swiss) ', 'locale' => 'it_ch', 'localeFallback' => 'ita', 'charset' => 'utf-8'),
266:                                         'ja' => array('language' => 'Japanese', 'locale' => 'jpn', 'localeFallback' => 'jpn', 'charset' => 'utf-8'),
267:                                         'ko' => array('language' => 'Korean', 'locale' => 'kor', 'localeFallback' => 'kor', 'charset' => 'kr'),
268:                                         'ko-kp' => array('language' => 'Korea (North)', 'locale' => 'ko_kp', 'localeFallback' => 'kor', 'charset' => 'kr'),
269:                                         'ko-kr' => array('language' => 'Korea (South)', 'locale' => 'ko_kr', 'localeFallback' => 'kor', 'charset' => 'kr'),
270:                                         'koi8-r' => array('language' => 'Russian', 'locale' => 'koi8_r', 'localeFallback' => 'rus', 'charset' => 'koi8-r'),
271:                                         'lt' => array('language' => 'Lithuanian', 'locale' => 'lit', 'localeFallback' => 'lit', 'charset' => 'utf-8'),
272:                                         'lv' => array('language' => 'Latvian', 'locale' => 'lav', 'localeFallback' => 'lav', 'charset' => 'utf-8'),
273:                                         'mk' => array('language' => 'FYRO Macedonian', 'locale' => 'mk', 'localeFallback' => 'mac', 'charset' => 'utf-8'),
274:                                         'mk-mk' => array('language' => 'Macedonian', 'locale' => 'mk_mk', 'localeFallback' => 'mac', 'charset' => 'utf-8'),
275:                                         'ms' => array('language' => 'Malaysian', 'locale' => 'may', 'localeFallback' => 'may', 'charset' => 'utf-8'),
276:                                         'mt' => array('language' => 'Maltese', 'locale' => 'mlt', 'localeFallback' => 'mlt', 'charset' => 'utf-8'),
277:                                         'n' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8'),
278:                                         'nb' => array('language' => 'Norwegian Bokmal', 'locale' => 'nob', 'localeFallback' => 'nor', 'charset' => 'utf-8'),
279:                                         'nl' => array('language' => 'Dutch (Standard)', 'locale' => 'dut', 'localeFallback' => 'dut', 'charset' => 'utf-8'),
280:                                         'nl-be' => array('language' => 'Dutch (Belgium)', 'locale' => 'nl_be', 'localeFallback' => 'dut', 'charset' => 'utf-8'),
281:                                         'nn' => array('language' => 'Norwegian Nynorsk', 'locale' => 'nno', 'localeFallback' => 'nor', 'charset' => 'utf-8'),
282:                                         'no' => array('language' => 'Norwegian', 'locale' => 'nor', 'localeFallback' => 'nor', 'charset' => 'utf-8'),
283:                                         'p' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8'),
284:                                         'pl' => array('language' => 'Polish', 'locale' => 'pol', 'localeFallback' => 'pol', 'charset' => 'utf-8'),
285:                                         'pt' => array('language' => 'Portuguese (Portugal)', 'locale' => 'por', 'localeFallback' => 'por', 'charset' => 'utf-8'),
286:                                         'pt-br' => array('language' => 'Portuguese (Brazil)', 'locale' => 'pt_br', 'localeFallback' => 'por', 'charset' => 'utf-8'),
287:                                         'rm' => array('language' => 'Rhaeto-Romanic', 'locale' => 'roh', 'localeFallback' => 'roh', 'charset' => 'utf-8'),
288:                                         'ro' => array('language' => 'Romanian', 'locale' => 'rum', 'localeFallback' => 'rum', 'charset' => 'utf-8'),
289:                                         'ru' => array('language' => 'Russian', 'locale' => 'rus', 'localeFallback' => 'rus', 'charset' => 'utf-8'),
290:                                         'ro-mo' => array('language' => 'Romanian (Moldavia)', 'locale' => 'ro_mo', 'localeFallback' => 'rum', 'charset' => 'utf-8'),
291:                                         'ru-mo' => array('language' => 'Russian (Moldavia)', 'locale' => 'ru_mo', 'localeFallback' => 'rus', 'charset' => 'utf-8'),
292:                                         'sb' => array('language' => 'Sorbian', 'locale' => 'wen', 'localeFallback' => 'wen', 'charset' => 'utf-8'),
293:                                         'sk' => array('language' => 'Slovak', 'locale' => 'slo', 'localeFallback' => 'slo', 'charset' => 'utf-8'),
294:                                         'sl' => array('language' => 'Slovenian', 'locale' => 'slv', 'localeFallback' => 'slv', 'charset' => 'utf-8'),
295:                                         'sq' => array('language' => 'Albanian', 'locale' => 'alb', 'localeFallback' => 'alb', 'charset' => 'utf-8'),
296:                                         'sr' => array('language' => 'Serbian', 'locale' => 'scc', 'localeFallback' => 'scc', 'charset' => 'utf-8'),
297:                                         'sv' => array('language' => 'Swedish', 'locale' => 'swe', 'localeFallback' => 'swe', 'charset' => 'utf-8'),
298:                                         'sv-fi' => array('language' => 'Swedish (Finland)', 'locale' => 'sv_fi', 'localeFallback' => 'swe', 'charset' => 'utf-8'),
299:                                         'sx' => array('language' => 'Sutu', 'locale' => 'sx', 'localeFallback' => 'sx', 'charset' => 'utf-8'),
300:                                         'sz' => array('language' => 'Sami (Lappish)', 'locale' => 'smi', 'localeFallback' => 'smi', 'charset' => 'utf-8'),
301:                                         'th' => array('language' => 'Thai', 'locale' => 'tha', 'localeFallback' => 'tha', 'charset' => 'utf-8'),
302:                                         'tn' => array('language' => 'Tswana', 'locale' => 'tsn', 'localeFallback' => 'tsn', 'charset' => 'utf-8'),
303:                                         'tr' => array('language' => 'Turkish', 'locale' => 'tur', 'localeFallback' => 'tur', 'charset' => 'utf-8'),
304:                                         'ts' => array('language' => 'Tsonga', 'locale' => 'tso', 'localeFallback' => 'tso', 'charset' => 'utf-8'),
305:                                         'uk' => array('language' => 'Ukrainian', 'locale' => 'ukr', 'localeFallback' => 'ukr', 'charset' => 'utf-8'),
306:                                         'ur' => array('language' => 'Urdu', 'locale' => 'urd', 'localeFallback' => 'urd', 'charset' => 'utf-8'),
307:                                         've' => array('language' => 'Venda', 'locale' => 'ven', 'localeFallback' => 'ven', 'charset' => 'utf-8'),
308:                                         'vi' => array('language' => 'Vietnamese', 'locale' => 'vie', 'localeFallback' => 'vie', 'charset' => 'utf-8'),
309:                                         'xh' => array('language' => 'Xhosa', 'locale' => 'xho', 'localeFallback' => 'xho', 'charset' => 'utf-8'),
310:                                         'cy' => array('language' => 'Welsh', 'locale' => 'cym', 'localeFallback' => 'cym', 'charset' => 'utf-8'),
311:                                         'yi' => array('language' => 'Yiddish', 'locale' => 'yid', 'localeFallback' => 'yid', 'charset' => 'utf-8'),
312:                                         'zh' => array('language' => 'Chinese', 'locale' => 'chi', 'localeFallback' => 'chi', 'charset' => 'utf-8'),
313:                                         'zh-cn' => array('language' => 'Chinese (PRC)', 'locale' => 'zh_cn', 'localeFallback' => 'chi', 'charset' => 'GB2312'),
314:                                         'zh-hk' => array('language' => 'Chinese (Hong Kong)', 'locale' => 'zh_hk', 'localeFallback' => 'chi', 'charset' => 'utf-8'),
315:                                         'zh-sg' => array('language' => 'Chinese (Singapore)', 'locale' => 'zh_sg', 'localeFallback' => 'chi', 'charset' => 'utf-8'),
316:                                         'zh-tw' => array('language' => 'Chinese (Taiwan)', 'locale' => 'zh_tw', 'localeFallback' => 'chi', 'charset' => 'utf-8'),
317:                                         'zu' => array('language' => 'Zulu', 'locale' => 'zul', 'localeFallback' => 'zul', 'charset' => 'utf-8'));
318: /**
319:  * Class constructor
320:  */
321:     function __construct() {
322:         if (defined('DEFAULT_LANGUAGE')) {
323:             $this->default = DEFAULT_LANGUAGE;
324:         }
325:         parent::__construct();
326:     }
327: /**
328:  * Gets the settings for $language.
329:  * If $language is null it attempt to get settings from I10n::__autoLanguage(); if this fails
330:  * the method will get the settings from I10n::__setLanguage();
331:  *
332:  * @param string $language Language (if null will use DEFAULT_LANGUAGE if defined)
333:  * @access public
334:  */
335:     function get($language = null) {
336:         if ($language !== null) {
337:             return $this->__setLanguage($language);
338:         } elseif ($this->__autoLanguage() === false) {
339:             return $this->__setLanguage();
340:         }
341:     }
342: /**
343:  * Sets the class vars to correct values for $language.
344:  * If $language is null it will use the DEFAULT_LANGUAGE if defined
345:  *
346:  * @param string $language Language (if null will use DEFAULT_LANGUAGE if defined)
347:  * @access private
348:  */
349:     function __setLanguage($language = null) {
350:         $langKey = null;
351:         if ($language !== null && isset($this->__l10nMap[$language]) && isset($this->__l10nCatalog[$this->__l10nMap[$language]])) {
352:             $langKey = $this->__l10nMap[$language];
353:         } else if ($language !== null && isset($this->__l10nCatalog[$language])) {
354:             $langKey = $language;
355:         } else if (defined('DEFAULT_LANGUAGE')) {
356:             $langKey = $language = DEFAULT_LANGUAGE;
357:         }
358: 
359:         if ($langKey !== null && isset($this->__l10nCatalog[$langKey])) {
360:             $this->language = $this->__l10nCatalog[$langKey]['language'];
361:             $this->languagePath = array(
362:                 $this->__l10nCatalog[$langKey]['locale'],
363:                 $this->__l10nCatalog[$langKey]['localeFallback']
364:             );
365:             $this->lang = $language;
366:             $this->locale = $this->__l10nCatalog[$langKey]['locale'];
367:             $this->charset = $this->__l10nCatalog[$langKey]['charset'];
368:         } else {
369:             $this->lang = $language;
370:             $this->languagePath = array($language);
371:         }
372: 
373:         if ($this->default) {
374:             if (isset($this->__l10nMap[$this->default]) && isset($this->__l10nCatalog[$this->__l10nMap[$this->default]])) {
375:                 $this->languagePath[] = $this->__l10nCatalog[$this->__l10nMap[$this->default]]['localeFallback'];
376:             } else if (isset($this->__l10nCatalog[$this->default])) {
377:                 $this->languagePath[] = $this->__l10nCatalog[$this->default]['localeFallback'];
378:             }
379:         }
380:         $this->found = true;
381: 
382:         if (Configure::read('Config.language') === null) {
383:             Configure::write('Config.language', $this->lang);
384:         }
385: 
386:         if ($language) {
387:             return $language;
388:         }
389:     }
390: /**
391:  * Attempts to find the locale settings based on the HTTP_ACCEPT_LANGUAGE variable
392:  *
393:  * @return boolean Success
394:  * @access private
395:  */
396:     function __autoLanguage() {
397:         $_detectableLanguages = preg_split('/[,;]/', env('HTTP_ACCEPT_LANGUAGE'));
398:         foreach ($_detectableLanguages as $key => $langKey) {
399:             $langKey = strtolower($langKey);
400:             if (strpos($langKey, '_') !== false) {
401:                 $langKey = str_replace('_', '-', $langKey);
402:             }
403: 
404:             if (isset($this->__l10nCatalog[$langKey])) {
405:                 $this->__setLanguage($langKey);
406:                 return true;
407:             } else if (strpos($langKey, '-') !== false) {
408:                 $langKey = substr($langKey, 0, 2);
409:                 if (isset($this->__l10nCatalog[$langKey])) {
410:                     $this->__setLanguage($langKey);
411:                     return true;
412:                 }
413:             }
414:         }
415:         return false;
416:     }
417: /**
418:  * Attempts to find locale for language, or language for locale
419:  *
420:  * @param mixed $mixed 2/3 char string (language/locale), array of those strings, or null
421:  * @return mixed string language/locale, array of those values, whole map as an array, or false when language/locale doesn't exist
422:  * @access public
423:  */
424:     function map($mixed = null) {
425:         if (is_array($mixed)) {
426:             $result = array();
427:             foreach ($mixed as $_mixed) {
428:                 if ($_result = $this->map($_mixed)) {
429:                     $result[$_mixed] = $_result;
430:                 }
431:             }
432:             return $result;
433:         } else if (is_string($mixed)) {
434:             if (strlen($mixed) === 2 && in_array($mixed, $this->__l10nMap)) {
435:                 return array_search($mixed, $this->__l10nMap);
436:             } else if (isset($this->__l10nMap[$mixed])) {
437:                 return $this->__l10nMap[$mixed];
438:             }
439:             return false;
440:         }
441:         return $this->__l10nMap;
442:     }
443: /**
444:  * Attempts to find catalog record for requested language
445:  *
446:  * @param mixed $language string requested language, array of requested languages, or null for whole catalog
447:  * @return mixed array catalog record for requested language, array of catalog records, whole catalog, or false when language doesn't exist
448:  */
449:     function catalog($language = null) {
450:         if (is_array($language)) {
451:             $result = array();
452:             foreach ($language as $_language) {
453:                 if ($_result = $this->catalog($_language)) {
454:                     $result[$_language] = $_result;
455:                 }
456:             }
457:             return $result;
458:         } else if (is_string($language)) {
459:             if (isset($this->__l10nCatalog[$language])) {
460:                 return $this->__l10nCatalog[$language];
461:             }
462:             return false;
463:         }
464:         return $this->__l10nCatalog;
465:     }
466: }
467: ?>